package com.oocl.FTP;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class FtpClent {

	public static void main(String[] args) throws Exception
	{
		final String PATH="download/";
		Socket socket=new Socket("127.0.0.1",8001);
		
		OutputStream out=socket.getOutputStream();
		InputStream in=socket.getInputStream();
		BufferedReader reader=new BufferedReader(new InputStreamReader(in));
		
		Scanner scanner=new Scanner(System.in);
		String tip=null;
		String filename=null;
		
		tip=reader.readLine();
		System.out.println(tip);
		
		String code=scanner.nextLine();
		if(code.startsWith("SCP"))
		{
			String[] strs=code.split(" ");
			filename=strs[1];
			File file=new File(PATH+filename);
			
			out.write((strs[2]+"//"+filename+"\n").getBytes());
			
			InputStream fin=new FileInputStream(file);
			byte[] buf=new byte[fin.available()];
			fin.read(buf); 
			out.write(buf);
			
			fin.close();
			System.out.println("成功上传到服务器");
		}
		out.close();
		reader.close();
		socket.close();
	}

}






